<template>
	<view class="pages">
		<view class="pages_logoBox">
			<image src="/static/img/logo.gif"></image>
			<image src="/static/img/logotext.png"></image>
		</view>
	</view>
</template>

<script>
	export default {
		components: {

		},
		data() {
			return {
				seven: 7 * 24 * 60 * 60 * 1000,
				masterId: '',
				priceId: ''

			}
		},
		onLoad(oprtion) {
			// #ifndef H5
			let search = uni.getMenuButtonBoundingClientRect()
			this.$store.commit('updataSearch', search);
			// #endif
			let that = this;
			let location = uni.getStorageSync('location');
			console.log(oprtion)
			if (oprtion.masterId && oprtion.priceId) {
				this.masterId = oprtion.masterId;
				this.priceId = oprtion.priceId;
				this.getAssist();
			}


			if (!location) {
				uni.getFuzzyLocation({
					type: 'gcj02', //返回可以用于uni.openLocation的经纬度
					success: (res) => {
						this.$qqmapsdk.reverseGeocoder({
							//把你的经纬度
							location: {
								latitude: res.latitude,
								longitude: res.longitude
							},
							success(qqmapsdkRes) {
								let city = qqmapsdkRes.result.address_component.city.replace('市', '');
								that.$api.userLocation({
									city
								}).then(res => {
									if (res.code == 200) {
										uni.setStorageSync('location', res.data
											.location);
										uni.setStorageSync('locationCity', res.data
											.location);
										that.$store.commit('updatalocation', res
											.data.location);
										that.$store.commit('updataUser', res.data
											.user);
										// 是否有加入社群
										if (that.user) {
											if (that.user.communityList && that.user
												.communityList.length != 0) {
												that.goIndex();
											} else {
												that.goSEM();
											}
										} else {
											that.goSEM();
										}
									}
								})

							}
						})
					},
					fail() {
						that.goSEM();
					}
				});
			} else {
				that.$api.userLocation({
					city: location.name
				}).then(res => {
					if (res.code == 200) {
						uni.setStorageSync('location', res.data
							.location);
						that.$store.commit('updatalocation', res
							.data.location);
						that.$store.commit('updataUser', res.data
							.user);
						// 是否有加入社群
						if (that.user) {
							if (that.user.communityList && that.user
								.communityList.length != 0) {
								that.goIndex();
							} else {
								that.goSEM();
							}
						} else {
							that.goSEM();
						}
					}
				})


			}
		},
		computed: {
			search() {
				return this.$store.state.search;
			},
			user() {
				return this.$store.state.user;
			},


		},
		methods: {
			getAssist() {
				return new Promise((ress, rejj) => {
					let req = {
						masterId: this.masterId,
						priceId: this.priceId
					}
					console.log('req--->', req)
					this.$api.getAssist(req).then(res => {
						if (res.code == 200) {
							uni.showToast({
								title: res.msg,
								icon: 'none',
								mask: true
							})
							ress();
						} else if (res.code == 503) {
							ress();
						}
					})
				})
			},
			goSEM() {
				console.log('跳转marketing')
				let passTime = uni.getStorageSync('passTime');
				if (passTime) {
					let nowTime = new Date().getTime();
					let diffTime = nowTime - passTime;
					// 小于7天
					if (diffTime < this.seven) {
						this.goIndex();
						return;
					}


				}
				uni.redirectTo({
					url: '/package/marketing/index'
				})
			},
			goIndex() {
				console.log('跳转index')
				uni.switchTab({
					url: '/pages/index/index'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.pages {
		min-height: 100vh;
		display: flex;
		justify-content: center;
		align-items: center;
		width: 100%;

		.pages_logoBox {
			display: flex;
			flex-direction: column;
			align-items: center;
			transform: translateY(-30%);

			image:nth-child(1) {
				width: 350rpx;
				height: 350rpx;
			}

			image:nth-child(2) {
				width: 214rpx;
				height: 40rpx;
			}
		}

	}
</style>
